/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年12月14日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20191214_fastsort
 * @Desc
 * @author 52489
 * @date 2019年12月14日
 * @Version V1.0
 */
public class A20191214_fastsort {

    public static void main(String[] args) {
        int[] nums = { 3, 2, 1, 7, 8, 4, 6, 5 };
        fastSort(nums, 0, nums.length - 1);
        System.out.println(Arrays.toString(nums));
    }

    /**
     * @param is
     * @param i
     * @param j
     */
    private static void fastSort(int[] nums, int start, int end) {
        if (start < end) {
            int leftIdx = start;
            int rightIdx = end;
            int tmp = nums[leftIdx];
            while (leftIdx < rightIdx) {
                while (nums[rightIdx] > tmp && rightIdx > leftIdx) {
                    rightIdx--;
                }
                while (nums[leftIdx] <= tmp && rightIdx > leftIdx) {
                    leftIdx++;
                }
                int k = nums[leftIdx];
                nums[leftIdx] = nums[rightIdx];
                nums[rightIdx] = k;
            }
            nums[start] = nums[leftIdx];
            nums[leftIdx] = tmp;
            fastSort(nums, start, leftIdx);
            fastSort(nums, leftIdx + 1, end);
        }
    }

}
